<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
﻿<!DOCTYPE HTML>
<html>
<head>
<jsp:include page="common_header.jsp" flush="true"></jsp:include>
<title>数据字典</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	系统管理
	<span class="c-gray en">&gt;</span>
	数据字典
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
	<div class="text-c"> 字典名称:
		<input type="text" class="input-text" id="" name="" style="width:150px">
		表名:
<!-- 		<span class="select-box inline"> -->
<!-- 		<select class="select" id="" name=""> -->
<!-- 			<option value="0">选择一个系统表名</option> -->
<!-- 			<option value="AccountInfo">AccountInfo</option> -->
<!-- 			<option value="AdminInfo">AdminInfo</option> -->
<!-- 		</select> -->
<!-- 		</span> -->
<!-- 		字段名: -->
<!-- 		<span class="select-box inline"> -->
<!-- 		<select class="select" id="" name=""> -->
<!-- 		</select> -->
<!-- 		</span> -->
		<input type="hidden" id="" name="">
		<button type="button" class="btn btn-primary radius" id="" name=""><i class="Hui-iconfont">&#xe600;</i> 添加字典</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a href="javascript:;" onclick="batchDel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
			<a class="btn btn-primary radius" href="javascript:;" onclick="layer_show('添加数据字典','${path}/user/toPage.do?page=system-data-add','800')"><i class="Hui-iconfont">&#xe600;</i> 添加字典项</a> </span>
		</span>
		<span class="r">共有数据：<strong id="totalRow">-</strong> 条</span>
	</div>
	<div class="mt-20">
		<table id="dictTbl" class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value="" onclick="checkAll(this)"></th>
					<th width="80">序号</th>
					<th>字典项类型</th>
					<th width="105">字典项代码</th>
					<th width="105">字典项名称</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
	</div>
</div>
<jsp:include page="_footer.jsp" flush="true"></jsp:include>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${path }/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">
// $('.table-sort').dataTable({
// 	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
// 	"bStateSave": true,//状态保存
// 	"aoColumnDefs": [
// 	  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
// 	  {"orderable":false,"aTargets":[0,5]}// 制定列不参与排序
// 	]
// });

$(function(){
	initDg('dictTbl', {
		queryUrl : '${path}/sysDict/query.do',
		beforeAjax : function(data){
// 			data.begin = $('#datemin').val();
//         	data.end = $('#datemax').val();
//         	data.keywords = $('#keywords').val();
		},
		sucessAjax : function(result){
			$('#totalRow').html(result.data.recordsTotal);
		},
		columns: [
            { "data": null },
            { "data": null },
            { "data": "queryCode" },
            { "data": "itemCode" },
            { "data": "itemName" },
            { "data": null }
        ],
        rowCallback : function(row, data, index){
        	var oper = '<a style="text-decoration:none" onclick="system_data_edit(\'编辑数据字典\',\'${path}/user/toPage.do?page=system-data-add\',\''+data.id+'\',\'400\',\'310\')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> ';
        	oper += '<a title="删除" href="javascript:;" onclick="system_data_del(this,\''+data.id+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
    		$('td:eq(5)', row).html( oper );
        }
	});
});

/**
 * 子页面调用父页面该方法
 */
function refresh(index){
	queryUser();
	layer.close(index);
}

/**
 * 触发dataTable的查询
 */
function queryUser(){
	$("#dictTbl").dataTable().fnDraw(false);
}



/*数据字典-编辑*/
function system_data_edit(title,url,id,w,h){
	w= 550;
	h= 270;
	layer.open({
		type: 2,
		area: [w+'px', h +'px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url,
		success: function(layero, index){
		    var body = layer.getChildFrame('body', index);
		    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
		    iframeWin.fillData(id);
// 		    console.log(body.html()) //得到iframe页的body内容
// 		    body.find('input').val('Hi，我是从父页来的')
	    }
	});
}
/*数据字典-删除*/
function system_data_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}

function batchDel(){
	var idArr = [];
	$('#dictTbl tbody :checked').each(function(){
		idArr.push($(this).next().val());
	});
	if (idArr.length > 0) {
		layer.confirm('确认要删除这'+idArr.length+'条记录吗？',function(index){
			$.ajax({
				url: '${path}/sysDict/delete.do',
				data: 'ids='+idArr.join(','), 
				type: "POST",
				success: function(data, textStatus){
					if (data.code == 0) {
						layer.msg('已删除!',{icon:1,time:1000});
						queryUser();
					}else{
						layer.msg('删除失败!',{icon:1,time:1000});
					}
				},
				error: function (data, textStatus, errorThrown) {
					var s=JSON.stringify(data);
				}
			});			
		});
	}else{
		layer.alert('请选择记录!',{icon:1,time:2000});
	}
}
</script>
</body>
</html>
